<template>
    <el-main>
      <el-table ref="multipleTable" tooltip-effect="dark" 
      :data="tableData"
      @selection-change="handleSelectionChange"
      border style="width: 100%"
      row-key="getRowKey">
        <el-table-column type="selection" :reserve-selection="true" width="55"></el-table-column>
        <el-table-column prop="id" label="u_id" width="100"></el-table-column>
        <el-table-column prop="nickname" label="昵称"></el-table-column>
        <el-table-column prop="userid" label="账号"></el-table-column>
        <el-table-column prop="password" label="密码"></el-table-column>
        <el-table-column prop="header" label="头像" ></el-table-column>
        <el-table-column prop="level" label="等级"></el-table-column>
      </el-table>
    </el-main>
</template>
<script>


  export default {
    //name:'refresh',
    data() {
      return {
        tableData:[],
        pager:{
          _page:1,
          _limit:10
      }
      }
    },
    created(){
      //获取数据
      // this.$http.get('http://localhost:3000/user').then(res=>{
      //   this.tableData = res.data
      // })
     this.query()
      //console.log(this.tableData);
      
      
    },
    //注入
    inject:['reload'],
    methods: {
       toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);//回显操作
          });
        } else {
          this.$refs.multipleTable.clearSelection();//清除回显
        }
      },
      //多选框被选中触发，参数为selection，可获取选中行的数据，数组类型，多选后，会将选中的每行都放进数组里面，数组套数组。
      //可通过selection.length获取选中的行数量从而去做一些判断
      handleSelectionChange(selection) {
        this.selectionNum = selection.length;
        this.selection = selection;
      },
      getRowKey(row){
        return row.id;
      },
      query(){
         this.$api.__api_list_users_get(this.pager).then(res=>{
        this.tableData = res
        })
      },// 当前页改变时触发 跳转其他页
      handleCurrentChange(val){
        this.pager._page = val;
        this.query()
        console.log(this.pager);
        console.log('每页 ${val} 条');
      },
      //刷新
      refresh(){
        this.reload()
      },
    },
  };
</script>

<style>
.el-main {
    display: block;
    flex: 1;
    flex-basis: auto;
    overflow: auto;
    box-sizing: auto;
    padding: 10px;
    line-height: 45px !important;
}
.el-table {
   width: 100% ;
}
</style>


